/*
 *说明：用户信息表 首页脚本
 *
 *@author liuxun 2012-03-06
*/

var opeForm;
var grid;

$(function(){
	opeForm = $('#opeForm');

	grid=$('#listTable').datagrid({
		frozenColumns:[[
            {title:'选择',field:'ck',checkbox:true}
		]],
		columns:[[

            {title:'身份证号',field:'org_code',align:'center',width:80},
            
            {title:'姓名',field:'org_name',align:'center',width:40},
            
            {title:'手机号',field:'mobile',align:'center',width:60},

            {title:'当前奖金',field:'remaining_bonus',align:'center',width:50},
            
            {title:'上月奖金',field:'last_extraction_bonus',align:'center',width:50},
            
            {title:'上上月奖金',field:'lastlast_extraction_bonus',align:'center',width:50},
            

            {title:'奖金总数',field:'totle_bonus',align:'center',width:50},
            
            {title:'所属银行',field:'bankname',align:'center',width:50},
            
            {title:'银行卡号',field:'banknumber',align:'center',width:50}
            
            
            //,

/*            {title:'提取次数',field:'extraction_time',align:'center',width:40},*/
            
/*            {title:'所处层级',field:'is_leader',align:'center',width:40},


            },*/

/*            {title:'最后一次提取日期',field:'last_extraction_data',align:'center',width:60},
            
            {title:'最后一次提取金额',field:'last_extraction_bonus',align:'center',width:60}*///, 
           

         /*   {title:'是否已经提取',field:'ifclear',align:'center',width:40} */
            
            /*
          
//            {title:'生效时间',field:'effect_time',align:'center',width:80},
//
//          {title:'失效时间',field:'expire_time',align:'center',width:80},

/*			{title:'操作',field:'operation',align:'center',width:40,
	        	formatter:function(value,rec){
         		var s = '<a style="cursor:pointer; color:blue" onclick=\'showInfo("' + rec.key + '")\'>查看明细</a>';
	        	    return s;
		   		}
		    }*/
        ]],
		singleSelect: false
	});

//	queryOperation_load();
 	queryOperation();

	$('#queryBtn').click(queryOperation);
	$('#clearBtn').click(clearOperation);
	$('#excute1').click(saveOperation);
	$('#excute2').click(exportOperation);
/*	$('#reloadBtn').click(refreshWin);*/
/*	$('#addBtn').click(addOperation);
	$('#editBtn').click(editOperation);*/
/* 	$('#deleteBtn').click(deleteOperation); */
});


//翻页时自动调用此函数
function saveOperation(){
    var options = { 
            url: 'A_ORG_BONUS!backup.do',
            type: 'post',
  		    success: function(backupMessage){
   
  				if (backupMessage == '1') {
  			 
  				showInfoWin('生成xls成功！');
  				} 
  				else
  				{
  				showInfoWin('生成xls失败！请联系开发人员！');
  				}
  			},
            error : function (XMLHttpRequest, textStatus, errorThrown) {
                
               showInfoWin('生成xls失败！出现异常！请联系开发人员！');  
            
 
            }
        };
        opeForm.ajaxSubmit(options);
}



//翻页时自动调用此函数
function exportOperation(){
	 
    var date = new Date();  
    var y = date.getFullYear();
	var m = date.getMonth()+1;
	var d = date.getDate();
 

 window.location.href="jsp/usraccount/a_org_bonus/bonus"+y+(m<10?('0'+m):m)+(d<10?('0'+d):d)+".xls";

}

//翻页时自动调用此函数
function onLoadPrev(msg){
	var queryParams=grid.datagrid('options').queryParams;
	queryParams['firstQuery']=false;
}

//查询操作
function queryOperation(){
//	alert('2222');
	var params = opeForm.serializeObject();
//	alert(params);
	grid.datagrid("options").pageNumber = 1;
	grid.datagrid({
		/*url: 'A_USR!queryList.do',*/
		url: 'A_ORG_BONUS!queryList.do',
		queryParams: jQuery.extend({}, params, {'firstQuery': true})
	});
}


function queryOperation_load(){
//	alert('2222');
	var params = opeForm.serializeObject();
	grid.datagrid("options").pageNumber = 1;
	grid.datagrid({
		/*url: 'A_USR!queryList.do',*/
		url: 'A_ORG_BONUS!queryList.do',
		queryParams: jQuery.extend({}, params, {'firstQuery': true})
	});
}


//清空操作（重置）
function clearOperation() {
	opeForm.resetForm();
}

//选择机构
function select_a_org() {
	var action = "A_ORG!showTree.do?model.org_status=01";
	var row = showModalWin(action);
	
	if (row) {
		$('#org_name').val(row.attributes.org_name);
		$('#org_sequence').val(row.attributes.org_sequence);
	}
	
}
//查看明细
function showInfo(key) {
	var url = 'A_USR!showInfo.do?model.key=' + key;
	openWin(url,'pop'); 
}

//添加用户信息表
function addOperation(){  
	var url = 'A_ORG!showAdd1.do';
	openWin(url,'pop');
}

//编辑用户信息表
function editOperation(){  
	var rows = grid.datagrid('getSelections');

	if (rows.length == 0) {
		showInfoWin('请您首先选中一条记录!');
		return;
	}  

	if (rows.length > 1) {
		showInfoWin('只能选择一条记录');
      	return; 
	}
	
	if (rows[0].usr_status == '03') {
		showInfoWin('已删除的用户不允许修改操作！');
      	return; 
	}

	var url = 'A_ORG!showEdit2.do?model.key=' + rows[0].key;
	openWin(url,'pop');
}   

//删除用户信息表
function deleteOperation() {
	var rows = grid.datagrid('getSelections');

	if (rows.length == 0) {
		showInfoWin('请您首先选中要清算的记录!');	
		return;
	}

	var ids = [];
	for (var i = 0; i < rows.length; i++) {
		ids.push(rows[i].key);
	}
	var params = $ .param({'id' : ids}, true);

	$ .messager.confirm('提示信息', '您确定要清算选定的' + rows.length + '条记录吗?', function(result){
		if(result){
			$ .ajax({
				url: 'A_ORG_BONUS!doPrizes.do',
				data: params,
				type: 'post',
				success: function(data){
				    showInfoWin('操作成功!');
					afterOK();
				}
			});
		}	
	});
}

//操作成功后刷新列表
function afterOK(){
	queryOperation();
}